//index.js
const app = getApp()

Page({
  data: {
    location:'定位中...',
    weatherArray: '加载中...',
    weather0:'',
    weather1:'',
    weather2:'',
    weather3:'',
    weather4:'',
    weather5:'',
    weather6:''
  },

  onLoad: function () {
    this.calcScrollHeight();
  },

  calcScrollHeight:function(){
    var that=this;
     //获取用户定位信息
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        console.log(longitude, latitude)
        wx.request({
          url: 'https://yiketianqi.com/api?version=v9&appid=51824594&appsecret=4AlWqIaF',
          header: {
            'content-type': 'application/json' // 默认值
          },
          success(res) {
            that.setData({
             location: res.data.city+'市',
             weatherArray:'更新时间: '+res.data.update_time,   
             weather0: res.data.data[0], 
             weather1: res.data.data[1],
             weather2: res.data.data[2],
             weather3: res.data.data[3],
             weather4: res.data.data[4],
             weather5: res.data.data[5],
             weather6: res.data.data[6]
            })
            console.log(res.data)      
          }
        })
      },  
    })
  },

  // 页面分享
  onShareAppMessage: function () {

  }
})
